package com.zhiche.lisa.mdm.controller.outer;

import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.mdm.dao.model.ServiceType;
import com.zhiche.lisa.mdm.service.IServiceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 服务类型 接口
 * @since 2018-06-01
 * @author lbl
 */
@RestController
@RequestMapping("/serviceType")
@Api(value = "/serviceType", description = "服务类型接口",tags={"服务类型接口"})
public class OutServiceTypeController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OutServiceTypeController.class);

    @Autowired
    private IServiceTypeService serviceTypeService;

    @GetMapping(value = "/getAllServiceType")
    @ApiOperation(value = "获取所有服务类型", notes = "获取所有服务类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<List<ServiceType>> getAllServiceType() {
        LOGGER.info("LspInfoController.getAllServiceType（获取所有服务类型） params : {} ");

        RestfulResponse<List<ServiceType>> result = new RestfulResponse<>(0,"success",null);

        try {
            String parentCode = "transportation";
            result.setData(serviceTypeService.getServiceType(parentCode));
        } catch (BaseException e) {
            LOGGER.error("LspInfoController.getAllServiceType ERROR... ", e);
            result = new RestfulResponse<>(-1, e.getMessage(), null);
        }

        return result;
    }

    @GetMapping(value = "/getServiceTypeByCode")
    @ApiOperation(value = "获取所有服务类型", notes = "获取所有服务类型", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<List<ServiceType>> getServiceTypeByCode(String codes) {
        LOGGER.info("LspInfoController.getServiceTypeByCode（获取所有服务类型） params : {} ");

        RestfulResponse<List<ServiceType>> result = new RestfulResponse<>(0,"success",null);

        try {
            result.setData(serviceTypeService.getServiceTypeByCodes(codes));
        } catch (BaseException e) {
            LOGGER.error("LspInfoController.getServiceTypeByCode ERROR... ", e);
            result = new RestfulResponse<>(-1, e.getMessage(), null);
        }

        return result;
    }
}
